﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WpfStarterKit.Framework.Navigation;

namespace WpfStarterKit.Framework.Commands
{
    /// <summary>
    /// The modal version of NavigationCommand. Calls NavigateModal instead of Navigate. To pass data to the called
    /// page, implement IProvideData.
    /// </summary>
    public class ModalNavigationCommand : NavigationCommand
    {
        /// <summary>
        /// Journal the current view? If this is set to false, the current view will not be journalled. Calling back
        /// on the next view will take the user to the current view's caller instead.
        /// </summary>
        public bool JournalCurrent { get; set; }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="action">Navigation action to execute on the NavigationManager</param>
        public ModalNavigationCommand(string action)
            : this(action, true, null, null)
        { }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="action">Navigation action to execute on the NavigationManager</param>
        /// <param name="journalCurrent">Journal the current view? If this is set to false, the current view will not be journalled. Calling back
        /// on the next view will take the user to the current view's caller instead.</param>
        public ModalNavigationCommand(string action, bool journalCurrent)
            : this(action, journalCurrent, null, null)
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="action">Navigation action to execute on the NavigationManager</param>
        /// <param name="execute">Business code to execute passed in as an instance of the Action delegate</param>
        public ModalNavigationCommand(string action, Action<object> execute)
            : this(action, true, execute, null)
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="action">Navigation action to execute on the NavigationManager</param>
        /// <param name="journalCurrent">Journal the current view? If this is set to false, the current view will not be journalled. Calling back
        /// on the next view will take the user to the current view's caller instead.</param>
        /// <param name="execute">Business code to execute passed in as an instance of the Action delegate</param>
        public ModalNavigationCommand(string action, bool journalCurrent, Action<object> execute)
            : this(action, journalCurrent, execute, null)
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="action">Navigation action to execute on the NavigationManager</param>
        /// <param name="execute">Business code to execute passed in as an instance of the Action delegate</param>
        /// <param name="canExecute">Predicate that determines whether the command can be executed</param>
        public ModalNavigationCommand(string action, Action<object> execute, Predicate<object> canExecute)
            : this(action, true, execute, canExecute)
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="action">Navigation action to execute on the NavigationManager</param>
        /// <param name="journalCurrent">Journal the current view? If this is set to false, the current view will not be journalled. Calling back
        /// on the next view will take the user to the current view's caller instead.</param>
        /// <param name="execute">Business code to execute passed in as an instance of the Action delegate</param>
        /// <param name="canExecute">Predicate that determines whether the command can be executed</param>
        public ModalNavigationCommand(string action, bool journalCurrent, Action<object> execute, Predicate<object> canExecute)
            : base(action, execute, canExecute)
        {
            JournalCurrent = journalCurrent;
        }

        /// <summary>
        /// Executes the command. Calls the NavigationAction associated with this command modally
        /// </summary>
        /// <param name="parameter">Parameter. Not used.</param>
        public override void Execute(object parameter)
        {
            RunExecuteHandler(parameter);
            ApplicationManager.Instance.Navigation.NavigateModal(NavigationAction, JournalCurrent);
        }
    }
}
